﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace Symbonix.NorSoNet.Security.BLL.Membership
{
    public class Occupation
    {
        public string Employer
        {
            get;
            set;
        }
        public string Position
        {
            get;
            set;
        }
        public string JobDescription
        {
            get;
            set;
        }
        public DateTime StartDate
        {
            get;
            set;
        }
        public DateTime? EndTime
        {
            get;
            set;
        }

        public Occupation()
        {
        }

        public Occupation(
            string employer,
            string position,
            string jobDescription,
            DateTime startTime,
            DateTime? endTime)
        {
            Employer = employer;
            Position = position;
            JobDescription = jobDescription;
            StartDate = startTime;
            EndTime = endTime;
        }

        public static string Serialize(List<Occupation> occupations)
        {
            if (occupations.Count == 0)
                return string.Empty;
            StringBuilder stringBuilder = new StringBuilder();
            XmlWriter xmlWriter = XmlWriter.Create(stringBuilder);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Occupation>));
            xmlSerializer.Serialize(xmlWriter, occupations);
            return stringBuilder.ToString();
        }

        public static List<Occupation> DeSerialize(string xml)
        {
            if (string.IsNullOrEmpty(xml))
                return new List<Occupation>();
            StringReader stringReader = new StringReader(xml);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Occupation>));
            return (List<Occupation>)xmlSerializer.Deserialize(stringReader);
        }
    }
}
